package com.zyf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyf.common.result.Result;
import com.zyf.model.user.UserInfo;
import com.zyf.service.UserinfoService;
import com.zyf.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/** 用户认证
 * @author zyf
 * @date 2021年05月28日 14:33
 */
@Api("用户认证")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserinfoService userinfoService;

    @ApiOperation(value = "分页条件查询用户信息Api")
    @GetMapping("/list/{page}/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页"),
            @ApiImplicitParam(name = "limit", value = "每页显示条数，默认 10"),
            @ApiImplicitParam(name = "userInfoQueryVo", value = "条件查询实体类")
    })
    public Result listUser(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           UserInfoQueryVo userInfoQueryVo
    ){
         Page<UserInfo> pageParam = new Page<>(page,limit);
         IPage<UserInfo> pageModel = userinfoService.selectUserByPage(pageParam,userInfoQueryVo);
         return Result.ok(pageModel);
    }

    @ApiOperation(value = "用户锁定")
    @GetMapping("/lock/{userId}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "status", value = "用户状态")
    })
    public Result lockUser(@PathVariable Long userId, @PathVariable Integer status){
        userinfoService.lockUser(userId,status);
        return Result.ok();
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("/show/{userId}")
    @ApiImplicitParam(name = "userId", value = "用户id")
    public Result showUser(@PathVariable Long userId){
        Map<String,Object> map = userinfoService.showUser(userId);
        return Result.ok(map);
    }

    @ApiOperation(value = "认证审批")
    @GetMapping("/approval/{userId}/{authStatus}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "authStatus", value = "用户认证状态")
    })
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus){
        userinfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
